<template>
  <div class="FlowNode-container">
    <template v-if="nodeConfig.type !== 99">
      <FlowCard v-model:node="nodeConfig"></FlowCard>
      <FlowAdd v-model:node="nodeConfig"></FlowAdd>
    </template>
    <template v-else>
      <div class="flex-row-xy-center">
        <div class="commonBtn-primary">流程结束</div>
      </div>
    </template>
  </div>
  <FlowNode
    v-if="nodeConfig.childNode && nodeConfig.childNode.nodeName"
    v-model:node="nodeConfig.childNode"
  ></FlowNode>
</template>

<script lang="ts" setup>
import FlowCard from "./FlowCard.vue";
import FlowAdd from "./FlowAdd.vue";
import {computed, watch} from "vue";

const props = defineProps({
  node: {
    type: Object,
    default: {}
  }
});

const emits = defineEmits(["update:node"]);
const nodeConfig = computed({
  get() {
    if (!props.node || !props.node.pkId) {
      return {
        pkId: "sid-start-node",
        nodeName: "流程发起",
        type: 0,
        priorityLevel: 0,
        settype: 0,
        selectMode: 0,
        selectRange: 0,
        examineRoleId: 0,
        directorLevel: 0,
        replaceByUp: 0,
        examineMode: 0,
        noHanderAction: 0,
        examineEndType: 0,
        examineEndRoleId: 0,
        examineEndDirectorLevel: 0,
        ccSelfSelectFlag: "",
        conditionList: [],
        nodeUserList: [],
        colnumPermissions: [],
        childNode: {
          pkId: "end-node",
          nodeName: "流程结束",
          type: 99
        },
        conditionNodes: []
      };
    }
    return props.node;
  },
  set(value) {
    emits("update:node", value);
  }
});

const init = () => {
  if (
    !nodeConfig.value.colnumPermissions ||
    !nodeConfig.value.colnumPermissions.length
  ) {
    if (nodeConfig.value.type === 0) {
      nodeConfig.value.colnumPermissions = [
        {
          model: "applyuser",
          name: "申请人",
          show: true,
          enabled: true
        }
      ];
    }
    if (nodeConfig.value.type === 1) {
      nodeConfig.value.colnumPermissions = [
        {
          model: "applyuser",
          name: "申请人",
          show: true,
          enabled: false
        }
      ];
    }
  }
};
// init()
</script>

<style lang="less" scoped>
.FlowNode-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #f1f1f1;
}
</style>
